package o;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.LinearLayout;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.gamereserve.bean.OrderAppCardBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailHiddenBean;
import com.huawei.appmarket.service.appdetail.view.widget.DetailDownloadButton;
import com.huawei.appmarket.service.appdetail.view.widget.DetailShareButton;
import com.huawei.appmarket.service.reserve.game.bean.WarmUpPageInfo;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import com.huawei.hwphy2d.physical.util.BarrierParameters;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.LinkedHashMap;
import java.util.Locale;
import o.bch.a;
import o.dge.d;
import o.ewm.i;
import o.ewm.j;
import o.ewm.n;

public class eew implements OnClickListener {
    private boolean ʻ = false;
    private SafeBroadcastReceiver ʻॱ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ eew ˊ;

        {
            this.ˊ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                if (dvq.ˊ().equals(intent.getAction()) && this.ˊ.ʽ != null) {
                    this.ˊ.ˏ(this.ˊ.ʽ.ॱ());
                }
            }
        }
    };
    private View ʼ;
    private DetailDownloadButton ʽ;
    private View ˊ;
    private LinearLayout ˊॱ;
    private Handler ˋ;
    private SafeBroadcastReceiver ˋॱ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ eew ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(intent.getAction())) {
                    Object stringExtra = intent.getStringExtra("ACTION_PARAM_COMMENT_REPLY_ADDED_TYPE_COMMENTID");
                    Object stringExtra2 = intent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_RATING");
                    Object stringExtra3 = intent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_CONTENT");
                    if (!TextUtils.isEmpty(stringExtra) && !TextUtils.isEmpty(stringExtra2) && this.ˋ.ᐝ != null) {
                        this.ˋ.ᐝ.ʼॱ(stringExtra);
                        this.ˋ.ᐝ.ˑ(stringExtra2);
                        if (!TextUtils.isEmpty(stringExtra3)) {
                            this.ˋ.ᐝ.ͺॱ(stringExtra3);
                        }
                    }
                }
            }
        }
    };
    private DetailShareButton ˎ;
    private View ˏ;
    private boolean ˏॱ = false;
    private WebView ͺ = null;
    private Context ॱ;
    private String ॱˊ = null;
    private SafeBroadcastReceiver ॱˋ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ eew ॱ;

        {
            this.ॱ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (intent != null) {
                String action = intent.getAction();
                if (("ACTION_RESERVE".equals(action) || "ACTION_CANCEL_RESERVE".equals(action)) && this.ॱ.ͺ != null) {
                    this.ॱ.ͺ.reload();
                }
            }
        }
    };
    private View ॱॱ;
    private DetailHiddenBean ᐝ;

    static /* synthetic */ class AnonymousClass4 {
        static final /* synthetic */ int[] ˋ = new int[cke.values().length];

        static {
            try {
                ˋ[cke.ˊॱ.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                ˋ[cke.ʼ.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                ˋ[cke.ͺ.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                ˋ[cke.ˋॱ.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
        }
    }

    public eew(Context context, Handler handler, WebView webView) {
        this.ॱ = context;
        this.ˋ = handler;
        this.ͺ = webView;
    }

    public void ˏ(LinearLayout linearLayout) {
        if (linearLayout == null) {
            this.ˏॱ = true;
            return;
        }
        this.ˊॱ = linearLayout;
        this.ˊ = linearLayout.findViewById(j.ﾟʽ);
        this.ʼ = linearLayout.findViewById(j.ﾞʽ);
        this.ˎ = (DetailShareButton) linearLayout.findViewById(j.ﾟʼ);
        this.ॱॱ = linearLayout.findViewById(j.ﾞʼ);
        this.ˏ = linearLayout.findViewById(j.ﾟʻ);
        this.ʽ = (DetailDownloadButton) linearLayout.findViewById(j.ﹶˋ);
        this.ˊ.setOnClickListener(this);
        this.ˊ.setTag(Integer.valueOf(0));
        this.ॱॱ.setOnClickListener(this);
        this.ॱॱ.setTag(Integer.valueOf(1));
        this.ˏ.setOnClickListener(this);
        this.ˏ.setTag(Integer.valueOf(2));
        ˏ();
        ᐝ();
        ʼ();
    }

    public void onClick(View view) {
        switch (((Integer) view.getTag()).intValue()) {
            case 0:
                if (this.ˎ != null) {
                    this.ˎ.ˋ(this.ͺ, this.ॱˊ);
                    return;
                }
                return;
            case 1:
                ͺ();
                return;
            case 2:
                String str = KeyAndValue.NUMBER_01;
                dgh.onEvent(new d(ContentManager.getInstant().getContext(), n.ᐝᐝ).ˏ(str + HiAnalyticsConstant.REPORT_VAL_SEPARATOR + 2).ˋ());
                dwk o_dwk = new dwk();
                if (this.ᐝ != null) {
                    o_dwk.ॱ(this.ᐝ.ॱـ());
                    LinkedHashMap linkedHashMap = new LinkedHashMap();
                    linkedHashMap.put(RpkInfo.APPID, this.ᐝ.ͺˏ());
                    linkedHashMap.put("type", String.valueOf(7));
                    linkedHashMap.put("service_type", String.valueOf(dgm.ˎ((Activity) view.getContext())));
                    linkedHashMap.put("detailid", this.ᐝ.ॱॱ());
                    dgh.ˋ("card_installbtn_click", linkedHashMap);
                }
                if (this.ʽ != null) {
                    ˏ(this.ʽ.ॱ());
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void ˏ() {
        ll.ˏ(this.ॱ).ˏ(this.ˋॱ, new IntentFilter("com.huawei.appmarket.service.broadcast.CommentAdded"));
    }

    private void ᐝ() {
        ll.ˏ(this.ॱ).ˏ(this.ʻॱ, new IntentFilter(dvq.ˊ()));
    }

    private void ʼ() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("ACTION_RESERVE");
        intentFilter.addAction("ACTION_CANCEL_RESERVE");
        ll.ˏ(this.ॱ).ˏ(this.ॱˋ, intentFilter);
    }

    public void ˊ(WarmUpPageInfo warmUpPageInfo, boolean z, String str) {
        if (warmUpPageInfo != null) {
            if (TextUtils.isEmpty(warmUpPageInfo.ᐝ()) || this.ˊॱ == null || this.ʽ == null) {
                Logger.e("ReserveWarmUpPageControl", "handleWarmUpGamePage error, warmUpPageInfo.packageName = " + warmUpPageInfo.ᐝ());
                return;
            }
            this.ˊॱ.setVisibility(0);
            OrderAppCardBean ˋ = ˋ(warmUpPageInfo);
            this.ʽ.setParam(ˋ);
            this.ʽ.ॱ();
            if (z) {
                this.ॱˊ = str;
                ˏ(ˋ);
                ˎ(ˋ);
            }
            if (this.ᐝ.ॱـ() != null) {
                drd.ˏ(this.ᐝ.ॱـ(), this.ᐝ.ˎˎ());
            }
            ˏ(this.ʽ.ॱ());
        }
    }

    public void ˎ() {
        try {
            ll.ˏ(this.ॱ).ˋ(this.ॱˋ);
            this.ͺ = null;
        } catch (Exception e) {
            Logger.ˋ("ReserveWarmUpPageControl", "unregisterReserveReceiver fail:" + e.toString());
        }
    }

    protected String ˋ(OrderAppCardBean orderAppCardBean, WarmUpPageInfo warmUpPageInfo) {
        float ॱ = (float) warmUpPageInfo.ॱ();
        if (!"zh".equals(dok.ᐝ()) && !"bo".equals(dok.ᐝ())) {
            return ˊ(ॱ);
        }
        ॱ = BarrierParameters.RESTITUTION;
        if (warmUpPageInfo.ॱ() > 1999) {
            ॱ = (float) epw.ˋ(((double) warmUpPageInfo.ॱ()) / 10000.0d, 1);
        }
        return ContentManager.getInstant().getContext().getResources().getQuantityString(i.ˊˋ, (int) ॱ, new Object[]{String.valueOf(ॱ)});
    }

    private String ˊ(float f) {
        String quantityString = ContentManager.getInstant().getContext().getResources().getQuantityString(i.ˋˊ, 1, new Object[]{Integer.valueOf(1)});
        int i;
        if (f >= ((float) 1000000)) {
            i = (int) (f / ((float) 1000000));
            return ContentManager.getInstant().getContext().getResources().getQuantityString(i.ˊˊ, i, new Object[]{Integer.valueOf(i)});
        } else if (f < ((float) 1000)) {
            return quantityString;
        } else {
            i = (int) (f / ((float) 1000));
            return ContentManager.getInstant().getContext().getResources().getQuantityString(i.ˋˊ, i, new Object[]{Integer.valueOf(i)});
        }
    }

    private OrderAppCardBean ˋ(WarmUpPageInfo warmUpPageInfo) {
        int i;
        OrderAppCardBean orderAppCardBean = new OrderAppCardBean();
        orderAppCardBean.ʽ(warmUpPageInfo.ʻ());
        orderAppCardBean.ˏˎ(warmUpPageInfo.ᐝ());
        orderAppCardBean.ˉ(warmUpPageInfo.ʽ());
        orderAppCardBean.ॱˊ(warmUpPageInfo.ˊ());
        orderAppCardBean.ʻ(warmUpPageInfo.ˊॱ());
        if (!TextUtils.isEmpty(warmUpPageInfo.ʼ())) {
            try {
                orderAppCardBean.ˏॱ(URLDecoder.decode(warmUpPageInfo.ʼ(), "UTF-8"));
            } catch (UnsupportedEncodingException e) {
                orderAppCardBean.ˏॱ(warmUpPageInfo.ʼ());
            }
        }
        orderAppCardBean.ॱ(warmUpPageInfo.ॱˊ());
        orderAppCardBean.ˋᐝ(warmUpPageInfo.ॱॱ());
        if (warmUpPageInfo.ˋ() == 0) {
            i = 1;
        } else {
            i = 0;
        }
        orderAppCardBean.ˏॱ(i);
        orderAppCardBean.ˋ(warmUpPageInfo.ˏॱ());
        orderAppCardBean.ˈ(ˋ(orderAppCardBean, warmUpPageInfo));
        orderAppCardBean.ˏ(4);
        if (efg.ˋ().ॱ(warmUpPageInfo.ᐝ()) != null) {
            orderAppCardBean.ˏॱ(1);
        } else {
            orderAppCardBean.ˏॱ(0);
        }
        return orderAppCardBean;
    }

    private void ˎ(OrderAppCardBean orderAppCardBean) {
        if (this.ˎ != null) {
            this.ˎ.setTitle(orderAppCardBean.v_());
            this.ˎ.setIcon(orderAppCardBean.ॱˌ());
            String ˋ = ˋ();
            this.ˎ.setShareContent(String.format(Locale.ENGLISH, this.ॱ.getResources().getString(n.ˉʻ), new Object[]{orderAppCardBean.v_(), ˋ}));
            this.ˎ.setAppId(orderAppCardBean.ͺˏ());
            this.ˎ.setVersion(orderAppCardBean.ˎˎ());
            this.ˎ.setPackageName(orderAppCardBean.ॱـ());
            if (orderAppCardBean.ͺ() == 1) {
                this.ˎ.setH5App(true);
            }
        }
    }

    private void ˏ(OrderAppCardBean orderAppCardBean) {
        this.ᐝ = new DetailHiddenBean();
        this.ᐝ.ˏ(orderAppCardBean.ͺ());
        this.ᐝ.ˉ(orderAppCardBean.ͺˏ());
        this.ᐝ.ॱᐝ(orderAppCardBean.ˎˎ());
        this.ᐝ.ˏˎ(orderAppCardBean.ॱـ());
        boolean z = UserSession.getInstance().isLoginSuccessful() && this.ᐝ.ㆍ() == null;
        if (z) {
            this.ʻ = false;
            ʽ();
        }
    }

    private void ʽ() {
        int ॱ = ccz.ॱ();
        if (this.ˎ.getContext() instanceof Activity) {
            ॱ = dgm.ˎ((Activity) this.ˎ.getContext());
        }
        String str = null;
        if (this.ᐝ.ॱـ() != null) {
            PackageInfo ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ(this.ᐝ.ॱـ());
            if (!(ᐝ == null || ᐝ.versionName == null)) {
                str = ᐝ.versionName;
            }
        }
        ((bcm) fho.ˏ().ˋ("AppComment").ॱ(bcm.class)).ॱ(this.ᐝ.ͺˏ(), str, 1, ॱ, new bcn(this) {
            final /* synthetic */ eew ˊ;

            {
                this.ˊ = r1;
            }

            public void ˊ(String str, String str2, String str3) {
                if (this.ˊ.ᐝ != null) {
                    this.ˊ.ᐝ.ˈ(UserSession.getInstance().getUserId());
                    this.ˊ.ᐝ.ˑ(str3);
                    this.ˊ.ᐝ.ͺॱ(str);
                    this.ˊ.ᐝ.ʼॱ(str2);
                }
            }
        });
    }

    private void ʻ() {
        if (doo.ˊ(ContentManager.getInstant().getContext())) {
            try {
                ((bci) fho.ˏ().ˋ("AppComment").ॱ(bci.class)).ॱ((Activity) this.ॱ, new a().ˋ(this.ᐝ.ͺˏ()).ॱ(this.ᐝ.ॱـ()).ˊ(this.ᐝ.ˎˎ()).ʼ(this.ᐝ.ㆍ()).ʻ(this.ᐝ.ꓸ()).ॱॱ(this.ᐝ.ꜟ()).ˎ(ॱॱ()).ˋ());
                return;
            } catch (Exception e) {
                Logger.e("ReserveWarmUpPageControl", "showCommentDialog error" + e.getMessage());
                return;
            }
        }
        evk.ˏ(ContentManager.getInstant().getContext(), n.ʹˊ, 0).ˋ();
    }

    private int ॱॱ() {
        if (this.ॱ == null || !(this.ॱ instanceof Activity) || ((Activity) this.ॱ).getWindow() == null) {
            return -1;
        }
        return ((Activity) this.ॱ).getWindow().getNavigationBarColor();
    }

    private void ͺ() {
        if (this.ᐝ != null) {
            if ((this.ॱ instanceof Activity) && dgm.ˏ((Activity) this.ॱ)) {
                dgh.ॱ(ContentManager.getInstant().getContext(), "01090606", "03");
            } else {
                dgh.onEvent(new d(ContentManager.getInstant().getContext(), n.ॱͺ).ˏ("03").ˋ());
            }
            if (this.ᐝ.ͺ() == 1 || erw.ˏ(this.ॱ, this.ᐝ.ॱـ())) {
                ʻ();
            } else {
                evk.ˏ(ContentManager.getInstant().getContext(), n.ᶥॱ, 0).ˋ();
            }
        }
    }

    private void ˏ(cke o_cke) {
        if (!this.ˏॱ && this.ᐝ != null) {
            switch (AnonymousClass4.ˋ[o_cke.ordinal()]) {
                case 1:
                case 2:
                case 3:
                case 4:
                    this.ˏ.setVisibility(0);
                    this.ʼ.setVisibility(8);
                    this.ˊ.setVisibility(8);
                    return;
                default:
                    this.ˏ.setVisibility(8);
                    if (this.ᐝ.ॱ() == 1) {
                        this.ˊ.setVisibility(8);
                        this.ʼ.setVisibility(0);
                        return;
                    }
                    this.ˊ.setVisibility(0);
                    return;
            }
        }
    }

    public void ˊ() {
        try {
            ll.ˏ(this.ॱ).ˋ(this.ˋॱ);
        } catch (Exception e) {
            Logger.e("ReserveWarmUpPageControl", "unregisterCommentReceiver fail:" + e.toString());
        }
    }

    public void ॱ() {
        try {
            ll.ˏ(this.ॱ).ˋ(this.ʻॱ);
            this.ͺ = null;
        } catch (Exception e) {
            Logger.ˋ("ReserveWarmUpPageControl", "unregisterDownloadReceiver fail:" + e.toString());
        }
    }

    public String ˋ() {
        return cwv.ॱ().ˋ();
    }
}
